import type {
  DoctorPage,
  KnowledgePage,
  KnowledgeParams,
  PageParams,
  FollowType,
  TopDep,
  Image,
  ConsultOrderPreParams,
  ConsultOrderPreData,
  PartialConsult,
  ConsultOrderItem,
  CosnultOrderListPatams,
  ConsultOrderPage,
} from '@/types/consult'
import { request } from '@/utils/request'

export const getKnowledgePage = (params: KnowledgeParams) => {
  return request.get<KnowledgePage>('/patient/home/knowledge', { params })
}

export const getDoctorPage = (params: PageParams) => {
  return request.get<DoctorPage>('/home/page/doc', { params })
}

export const followDcoctor = (id: string, type: FollowType = 'doc') => {
  return request.post('/like', { id, type })
}

export const getAllDep = () => {
  return request.get<TopDep[]>('/dep/all')
}

export const uploadImage = (file: File) => {
  const fd = new FormData()
  fd.append('file', file)
  return request.post<Image>('/upload', fd)
}

export const getConsultOrderPre = (params: ConsultOrderPreParams) => {
  return request.get<ConsultOrderPreData>('/patient/consult/order/pre', { params })
}

export const createConsultOrder = (data: PartialConsult) => {
  return request.post<{ id: string }>('/patient/consult/order', data)
}

export const getConsultOrderPayUrl = (data: {
  paymentMethod: 0 | 1
  orderId: string
  payCallback: string
}) => {
  return request.post<{ payUrl: string }>('/patient/consult/pay', data)
}

export const getConsultOrderDetail = (orderId: string) => {
  return request.get<ConsultOrderItem>('/patient/consult/order/detail', { params: { orderId } })
}

export const getPrescriptionPic = (id: string) => {
  return request.get<{ url: string }>(`/patient/consult/prescription/${id}`)
}

export const evaluateConsultOrder = (data: {
  docId: string // 医生ID
  orderId: string // 订单ID
  score: number // 评价星级
  content: string // 评价留言
  anonymousFlag: 0 | 1 // 是否匿名评价：1匿名 0实名
}) => {
  return request.post('/patient/order/evaluate', data)
}

export const getConsultOrderList = (params: CosnultOrderListPatams) => {
  return request.get<ConsultOrderPage>('/patient/consult/order/list', { params })
}

export const cancelOrder = (id: string) => {
  return request.put(`/patient/order/cancel/${id}`)
}

export const deleteOrder = (id: string) => {
  return request.delete(`/patient/order/${id}`)
}
